home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_13_04 / zeke2 / native.doc < prev    next >
Text File  |  1995-03-06  |  9KB  |  175 lines

  1. Class implementation under Windows/NT and Windows/3.1:
  2. ======================================================
  3.  
  4. As a prerequisite, the Windows environment requires that the application
  5. has a function WinMain.  In this function the library initializes its
  6. global variables, then creates argc, and argv from the command line.
  7. Finally it calls main() (which is redefined as ApplicationMain).
  8.  
  9. The GUI_APPLICATION class:
  10.  
  11. The constructor of the GUI_APPLICATION object first opens the log file.  It
  12. registers one window procedure, GuiWindowProc() for all of its windows
  13. using RegisterClass(), then queries the screen dimensions and the default
  14. font height. The MainLoop() function implements the main Windows
  15. message loop through GetMessage(), TranslateMessage, and DispatchMessage().
  16. The Terminate() function posts a quit message which in turn breaks the
  17. message loop.
  18.  
  19. The constructor of the GUI_WINDOW object creates a standard window using
  20. the CreateWindow() function and the earlier registered window class, and
  21. adds itself to the window list of the GUI_APPLICATION object.
  22.  
  23. The main window procedure:
  24.  
  25. Whenever a window needs to be repainted Windows delivers a WM_PAINT
  26. message to the window's window procedure, GuiWindowProc().  GuiWindowProc,
  27. in turn, calls the Paint() function of the GUI_WINDOW object which goes
  28. through the list of its children and calls the Paint() function for the
  29. ones which are not implemented as native windows.  (Namely for the GUI_LINE
  30. and for the GUI_ELLIPSE objects.)
  31.  
  32. Whenever the window is resized, Windows delivers a WM_PAINT and a WM_SIZE
  33. message. The WM_SIZE message is processed by calling the SizeChildren()
  34. function which recalculates the sizes of all native-window children.
  35.  
  36. Whenever the user activates a button or an entry field is losing focus,
  37. Windows sends a WM_COMMAND message to the window procedure.
  38. GuiWindowProc() finds the parent window for the object then the object
  39. itself and calls its Activate() function.
  40.  
  41. Graphical objects:
  42.  
  43. Windows expects the application to redraw the graphical objects
  44. GUI_LINE and GUI_ELLIPSE. Therefore, both of these classes have a
  45. non-trivial Paint() function which repaints the object. Their destructors
  46. invalidate the bounding rectangle of the object, so the next repaint of the
  47. parent window will erase them.
  48.  
  49. Non-graphical objects:
  50.  
  51. The implementation of the non-graphical, native-window using classes
  52. (GUI_TEXT, GUI_BUTTON, and GUI_ENTRY) are pretty straightforward. The only
  53. interesting point is that the library wants to catch all of the mouse
  54. events for buttons. In order to do so, it needs to override the built in
  55. window procedure for buttons.  Windows uses the term "subclassing the
  56. window" for this.  Hence, in the constructor of GUI_BUTTON it subclasses
  57. the window by providing its own window procedure, GuiButtonProc().  This
  58. new window procedure handles all of the messages what the library is
  59. interested in.  All other messages are sent to the original button window
  60. procedure, therefore the default behavior of the window is not changed.
  61.  
  62. Class implementation under OS/2 2.1:
  63. ====================================
  64.  
  65. The implementation is extremely similar to the Windows version.
  66.  
  67. The GUI_APPLICATION class:
  68.  
  69. The constructor of the GUI_APPLICATION object first opens the log file,
  70. uses the WinInitialize() function to initialize the application, then
  71. creates a message queue with the default queue-length using
  72. WinCreateMsgQueue().  It registers one window procedure, GuiWindowProc()
  73. for all of its windows using WinRegisterClass().  The MainLoop() function
  74. implements the main PM message loop through WinGetMsg() and
  75. WinDispatchMsg().  The Terminate() function posts a WM_CLOSE message to the
  76. first window of the application which in turn generates a WM_QUIT message,
  77. which breaks the message loop.
  78.  
  79. The constructor of the GUI_WINDOW object creates a standard window using
  80. the WinCreateStdWindow() function and the earlier registered window class,
  81. and adds itself to the window list of the GUI_APPLICATION object.
  82.  
  83. The main window procedure:
  84.  
  85. Whenever the window needs to be repainted PM delivers a WM_PAINT message
  86. to the window's window procedure, GuiWindowProc().  GuiWindowProc, in turn,
  87. calls the Paint() function of the GUI_WINDOW object which goes through the
  88. list of its children and calls the Paint() function for the ones which are
  89. not implemented as native windows.  (Namely for the GUI_LINE and
  90. the GUI_ELLIPSE objects.)
  91.  
  92. Whenever the window is resized, PM delivers a WM_PAINT and a WM_SIZE
  93. message. The WM_SIZE message is processed by calling the SizeChildren()
  94. function which recalculates the sizes of all native-window children.
  95.  
  96. Whenever the user activates a button, PM sends a WM_COMMAND message to the
  97. window procedure. GuiWindowProc() finds the parent window for the object
  98. then the object itself and calls its Activate() function.
  99.  
  100. Similarly, whenever an entry field loses focus, PM sends a WM_CONTROL
  101. message to the window procedure. As above, the entry field is found, then
  102. its Activate() function is called.
  103.  
  104. About graphical and non-graphical objects, see the Windows section since
  105. their handling is identical.
  106.  
  107. Class implementation under Motif 1.2 and X11R5:
  108. ===============================================
  109.  
  110. The GUI_APPLICATION class:
  111.  
  112. The constructor of the GUI_APPLICATION object first opens the log file,
  113. uses the XtAppInitialize() function to initialize the application and
  114. create an application shell, picks up the default font (can be set even
  115. through the command line), then allocates the VGA colors.  The MainLoop()
  116. function implements the main X message loop through XtAppNextEvent() and
  117. XtDispatchEvent().  The Terminate() function sets the dontQuit variable to
  118. 0 which breaks the main message loop.  To guarantee that there is at least
  119. one message in the message loop after the Terminate() functions returns,
  120. this function also sets up a timer which in turn generates an X message.
  121.  
  122. The constructor of the GUI_WINDOW object either creates a new toplevel
  123. shell or reuses the original shell widget as a frame, then creates a
  124. drawing are widget as its child.  It registers two callback functions,
  125. ResizeCallback() and ExposeCallback(), to handle the resizing and
  126. repainting of the window.  Finally, it allocates a graphics context for the
  127. window and adds itself to the window list of the GUI_APPLICATION object.
  128.  
  129. Whenever any part of the window needs to be repainted X calls the
  130. ExposeCallback() function.  This function collects the refreshable
  131. rectangles, then, in turn, calls the Paint() function of the GUI_WINDOW
  132. object which goes through the list of its children and calls the Paint()
  133. function for the ones which are not implemented as native windows.  (Namely
  134. for the GUI_LINE and the GUI_ELLIPSE objects.)
  135.  
  136. Whenever the window is resized, X calls the ResizeCallback() function. This
  137. function clears the entire window, then calls the SizeChildren() function
  138. which recalculates the sizes of all native-window children.
  139.  
  140. Whenever the user activates a button, X calls the functions registered
  141. with the button for the activate action.  In this case
  142. ButtonActivateCallback().  This function has an optional parameter where
  143. the library passes the object pointer.  Using this pointer as a GUI_BUTTON
  144. pointer, this function calls its Activate() function.
  145.  
  146. Similarly, whenever an entry field loses focus X calls the function
  147. which is registered for this action (EntryActivateCallback().)
  148.  
  149. Graphical objects:
  150.  
  151. X expects the application to redraw the graphical objects GUI_LINE and
  152. GUI_ELLIPSE.  Therefore, both of these classes have a non-trivial Paint()
  153. function which repaints the object.  Their destructors clears the bounding
  154. rectangle of the object, so the next repaint of the parent window will
  155. erase them.
  156.  
  157. Non-graphical objects:
  158.  
  159. The implementation of the non-graphical, native-window using classes
  160. (GUI_TEXT, GUI_BUTTON, and GUI_ENTRY) are pretty straightforward. The only
  161. interesting point is that the library wants to catch all of the mouse
  162. events for buttons. In order to do so, it needs to register an event
  163. handler, ButtonEventHandler(), to catch all of the mouse events.  Since the
  164. library wants to be able to provide left and right double click calls